package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "品牌分类管理")
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {

    @Autowired
    CategoryBrandService categoryBrandService;


    @Operation(summary = "根据第三级分类id，返回id集合（包含3个分类id）")
    @GetMapping("getIdsByCategory3Id/{category3Id}")
    public Result getIdByCategory3Id(@PathVariable Long category3Id){

        List<Long> idlist = categoryBrandService.getIdByCategory3Id(category3Id);
        return Result.build(idlist,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "新增品牌分类")
    @PostMapping("addCategoryBrand")
    public Result addCategoryBrand(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.addCategoryBrand(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询品牌分类列表")
    @PostMapping("{pageNum}/{pageSize}")
    public Result findByPage(@PathVariable Integer pageNum,
                             @PathVariable Integer pageSize,
                             @RequestBody CategoryBrandDto categoryBrandDto){
        PageInfo pageInfo = categoryBrandService.findByPage(pageNum,pageSize,categoryBrandDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    /*@PostMapping("deleted/{brandId}/categoryId")
    public Result deletedCategoryBrand(@PathVariable Long brandId,@PathVariable Long categoryId){
        categoryBrandService.deletedById(brandId,categoryId);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }*/

    @Operation(summary = "根据品牌和分类id删除数据")
    @PostMapping("deleted/{id}")
    public Result deletedCategoryBrand(@PathVariable Integer id){

        categoryBrandService.deletedById(id);

        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改品牌分类")
    @PostMapping("updateCategoryBrand")
    public Result updateCategoryBrand(@RequestBody CategoryBrand categoryBrand ){

        categoryBrandService.updateCategoryBrand(categoryBrand);

        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
